package com.xbongbong.saas.model;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.DepartmentVO;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.saas.domain.entity.ext.WarehouseEntityExt;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/22 16:44
 * @since v1.0
 */
public interface WarehouseModel extends IModel<WarehouseEntityExt> {
    /**
     * 仓库数据单条查询
     *
     * @param key    主键ID
     * @param corpid 公司ID
     * @return Integer
     * @author feng.zheng
     * @date 2019/2/15 20:27
     * @since v1.0
     */
    WarehouseEntityExt getByKey(Long key, String corpid);
    /**
     * 获取所有的仓库 默认增加一项【全部仓库】
     *
     * @param corpid 公司ID
     * @return Integer
     * @author feng.zheng
     * @date 2019/2/18 12:08
     * @since v1.0
     */
    JSONArray fillWarehouseArray(String corpid);

    /**
     * 获取仓库实体
     * @param param 查询条件
     * @return
     */
    @Override
    List<WarehouseEntityExt> findEntitys(Map<String, Object> param);

    /**
     * 根据idIn获取仓库实体
     * @param idIn
     * @param corpid 公司id
     * @return map, key为仓库id，value为warehouseObj{"id":1,"value":"李正的仓库"}
     */
    Map<Long, JSONObject> findWarehouseObjMapByIdIn(List<Long> idIn, String corpid);

    /**
     * 删除仓库
     * @author 吴峰
     * @date 2019/4/29 9:51
     * @param dataIdIn 数据列表
     * @param corpid 公司id
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer deleteBatch(List<Long> dataIdIn, String corpid) throws XbbException;

    /**
     * 单个删除
     * @param id
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer deleteByKey(Long id,String corpid) throws XbbException;

    JSONArray getWarehouseArray(String corpid);
    /**
    * @Description:  批量更新
    * @Param: [list, corpid]
    * @return: java.lang.Integer
    * @Author: cyy
    * @Date: 2019/11/11
    */
    Integer updateBatch(List<UpdateDataEntity> list, String corpid) throws XbbException;

    /**
     * 批量更新
     * @param list
     * @param corpid
     * @param refreshPolicy
     * @return 更新条数
     * @throws XbbException
     */
    Integer updateBatch(List<UpdateDataEntity> list, String corpid, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    Integer updateBatchImmediately(List<UpdateDataEntity> list, String corpid) throws XbbException;

    List findEntitysWithoutSub(Map<String, Object> param);

    /**
     * 编辑时将获取数据格式化
     *
     * @param saasAnalysisDataDTO saas编辑数据
     * @param result               要返回的jsonobject
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/22 15:28
     */
    void formatData(SaasAnalysisDataDTO saasAnalysisDataDTO, JSONObject result) throws XbbException;

    /**
     * 根据权限获取仓库
     * @param loginUser
     */
    List<Long> getWarehouseIdsByPermission(UserVO loginUser, Set<DepartmentVO> depSet) throws XbbException;
}
